/*
 * jQuery Toolbar 0.1
 * http://www.bsweb.com.cn
 * 需要库文件
 * 		jquery-ui.js
 * 		jquery-button.js
 */
(function($,undefined){
	$.widget("ui.toolbar",{
		options:{
			items:[]
		},
		_create:function(){
			this.toolbarPanel = this.element;
			this.toolbarPanel.append("<div class='toolbar-clearboth'/>");
		},
		_init:function(){
			var opts = this.options;
			if(opts.items.length > 0){
				for(var i = 0;i < opts.items.length;i++){
					this.addToolComponent(opts.items[i]);
				}
			}
		},
		_rsButton:function(btnObj){
			if($.trim(btnObj.type == '')){
				btnObj.typetype = "button";
			}
			if($.trim(btnObj.text) == ""){
				btnObj.text = "";
			}
			var toolBtn = "";
			if(btnObj.text == "-"){
				toolBtn = $("<div class='tool-separator'/>");
			}
			if(btnObj.type == "button"){
				toolBtn = $("<a>").button(btnObj);
				toolBtn.css("float","left");
//				toolBtn = "<a style='float:left;' href='javascript:void(0)' class='btn'>"+
//						  "<span class='btn-left'><span style='padding-left:20px;' class='btn-text'></span></span></a>";
//				toolBtn = $(toolBtn);
//				toolBtn.children("span").children("span").html(btnObj.text);
//				if($.trim(btnObj.iconCls) != ""){
//					toolBtn.children("span").children("span").addClass(btnObj.iconCls);
//				}
//				if($.isFunction(btnObj.handler)){
//					toolBtn.click(btnObj.handler);
//				}
			}
			return toolBtn;
		},
		addToolComponent:function(btnObj){
			if($.trim(btnObj.type == '')){
				btnObj.type = "button";
			}
			var toolCtx = "";
			
			if(btnObj.type == 'compGroup'){
				if(btnObj.items == undefined || btnObj.items == null || btnObj.items.length < 1){
					return;
				}
				toolCtx = $("<div />");
				if($.trim(btnObj.ctxCls) != ''){
					toolCtx.addClass(btnObj.ctxCls);
				}
				for(var i = 0;i < btnObj.items.length;i++){
					var tmpBtn = this._rsButton(btnObj.items[i]);
					
					toolCtx.append(tmpBtn);
				}
				toolCtx.append("<div class='toolbar-clearboth'/>");
			}else{
				toolCtx = this._rsButton(btnObj);
			}
			this.toolbarPanel.addClass("panel-toolbar");
			
			this.toolbarPanel.children(".toolbar-clearboth").before(toolCtx);
		},
		test:function(){
			alert("uuuuu");
		}
	})
})(jQuery)
